#ifdef FSHIGHPRECISION
precision highp float;
#else
precision mediump float;
#endif

uniform float u_Luminance;

#ifdef DIFFUSEMAP
varying vec2 v_Texcoord0;
uniform sampler2D u_DiffuseTexture;
#endif

#ifdef SPECULARMAP 
varying vec2 v_Texcoord1;
uniform sampler2D u_SpecularTexture;
#endif

#ifdef COLOR
varying vec4 v_Color;
#endif



#ifdef FOG
uniform float u_FogStart;
uniform float u_FogRange;
uniform vec3 u_FogColor;
#endif

void main()
{
  
  #if defined(DIFFUSEMAP)&&!defined(COLOR)
  gl_FragColor=texture2D(u_DiffuseTexture, v_Texcoord0);
  #endif 
  
  #if defined(COLOR)&&!defined(DIFFUSEMAP)
  gl_FragColor=v_Color;
  #endif 
  
  #ifdef defined(DIFFUSEMAP)&&defined(COLOR)
  vec4 texColor=texture2D(u_DiffuseTexture, v_Texcoord0);
  gl_FragColor=texColor*v_Color;
  #endif
  
  #ifdef SPECULARMAP 
  vec4 specularColor=texture2D(u_SpecularTexture, v_Texcoord1);
  gl_FragColor=gl_FragColor*specularColor;
  #endif
 
  gl_FragColor.rgb=gl_FragColor.rgb*u_Luminance;
  
  #ifdef FOG
  float lerpFact=clamp((toEyeLength-u_FogStart)/u_FogRange,0.0,1.0);
  gl_FragColor.rgb=mix(gl_FragColor.rgb,u_FogColor,lerpFact);
  #endif
}

